package com.ideal.manage.esms.controller;


import com.ideal.manage.esms.config.shiro.MyShiroRealm;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class HelloController {

    @RequestMapping({"/","/login"})
    public String login(HttpServletRequest request, Model model){
        String exception = (String) request.getAttribute("shiroLoginFailure");
        System.out.println(exception);
        if(exception != null && exception.equals("org.apache.shiro.authc.IncorrectCredentialsException")){
            model.addAttribute("error_msg","账号或密码错误");
        }
        MyShiroRealm.ShiroUser user = (MyShiroRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
        if (user != null) {
            return "main/index";
        } else {
            return "login";
        }
    }

}
